//
//  InspectionCell.m
//  ZZmetro
//
//  Created by 一介布衣 on 2020/6/26.
//  Copyright © 2020 一介布衣. All rights reserved.
//

#import "InspectionCell.h"
#import "TakePhotoController.h"

@interface InspectionCell()

@property (weak, nonatomic) IBOutlet UIView *verLineView;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UILabel *stationInfoLb;
@property (weak, nonatomic) IBOutlet UILabel *inspectionPersonLb;
@property (weak, nonatomic) IBOutlet UILabel *inspectionTimeLb;
@property (weak, nonatomic) IBOutlet UIButton *imgReuploadBtn;
@property (weak, nonatomic) IBOutlet UIImageView *inpspectionImg;
@property (weak, nonatomic) IBOutlet UIButton *takePhotoBtn;

@property (nonatomic, strong) InspectionPoint* inspectionPoint;
@property (nonatomic, assign) NSInteger index;

@end

@implementation InspectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _imgReuploadBtn.hidden = YES;
    _inpspectionImg.hidden = YES;
    _verLineView.backgroundColor = HEXCOLOR(0X5A7EEE);
    _lineView.backgroundColor = HEXCOLOR(0XDDDDDD);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (IBAction)reUploadImg:(id)sender {
    
}

- (IBAction)takePhoto:(id)sender {
    [Toast toast:@"take photo"];
    
    UINavigationController *navCtl = [UIViewController currentNavigationController];
    TakePhotoController *takeCtrl = [TakePhotoController new];
    CommonWeakSelf;
    takeCtrl.photoTokenBlcok = ^(UIImage *newIMG, NSString *path) {
        CommonStrongSelf;
        strongSelf.inspectionPoint.img = newIMG;
        strongSelf.inspectionPoint.imgPath = path;
        //[strongSelf bindData:strongSelf.inspectionPoint];
        if (strongSelf.dataChangedblock) {
            strongSelf.dataChangedblock(strongSelf.inspectionPoint, strongSelf.index);
        }
    };
    takeCtrl.pickType = 2;
    [navCtl pushViewController:takeCtrl animated:NO];
}

-(void) bindData:(InspectionPoint *)insPoint withIndex:(NSInteger) i {
    _inspectionPoint = insPoint;
    _stationInfoLb.text = insPoint.tourPointName;
    _inspectionPersonLb.text = insPoint.updateName;
    _inspectionTimeLb.text = insPoint.codeTime;
    if (insPoint.img) {
        _inpspectionImg.hidden = NO;
        _inpspectionImg.image = insPoint.img;
    } else {
        _inpspectionImg.hidden = YES;
    }
    
//    if (insPoint.imgPath) {
//        [_inpspectionImg sd_setImageWithURL:[NSURL fileURLWithPath: insPoint.imgPath]];
//    }
    
    _index = i;
}

@end
